package com.itheima.service.Impl;

import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.JobCountData;
import com.itheima.pojo.JobOption;
import com.itheima.pojo.StudentCountData;
import com.itheima.pojo.StudentOption;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;
    /**
     * 查询员工职位数据
     * @return
     */
    @Override
    public JobOption empJobData() {
        //返回的数据
        JobOption jobOption = new JobOption();
        List<JobCountData> jobCountData = empMapper.countEmpJobData();
        //设置jobList jobCountData转为字符串
        List<String> jobList = jobCountData.stream().map(JobCountData::getJobName).toList();
        jobOption.setJobList(jobList);
        //设置dataList
        List<String> dataList = jobCountData.stream().map(JobCountData::getNum).map(Object::toString).toList();
        jobOption.setDataList(dataList);
        return jobOption;
    }
    /**
     * 查询员工性别数据
     * @return
     */
    @Override
    public List<Map<String,Object>> getEmpGenderData() {
        return empMapper.getEmpGenderData();
    }

    /**
     * 查询学生学历数据
     * @return
     */
    @Override
    public List<Map<String, Object>> getStudentDegreeData() {
        return studentMapper.getStudentDegreeData();

    }
    /**
     * 统计班级人数
     * @return
     */

    @Override
    public StudentOption getStudentCountData() {
        StudentOption studentOption = new StudentOption();
        List<StudentCountData> clazzCountData = studentMapper.countStudentData();

        List<String> clazzList = clazzCountData.stream().map(StudentCountData::getClazzName).toList();
        studentOption.setClazzList(clazzList);

        List<Integer> dataList = clazzCountData.stream().map(StudentCountData::getNum).toList();
        studentOption.setDataList(dataList);

        return studentOption;
    }



}
